/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sembr.vtk.data.input;

import vtk.vtkCylinderSource;
import vtk.vtkDoubleArray;
import vtk.vtkPolyData;

/**
 *
 * @author adriano
 */
public class Cylinder extends SourceBase {
    
    private vtkCylinderSource cylinderSource;
    private double[] center;
    private double height;
    private double radius;
    private int resolution;
    private vtkPolyData triangulatedCylinder;
    private boolean cappingOn;
    
    public Cylinder() {
        this.cylinderSource = new vtkCylinderSource();
    }

    /**
     * @return the cylinderSource
     */
    public vtkCylinderSource getCylinderSource() {
        return cylinderSource;
    }

    /**
     * @param cylinderSource the cylinderSource to set
     */
    public void setCylinderSource() {        
        this.cylinderSource.SetCenter(getCenter());
        this.cylinderSource.SetHeight(getHeight());
        this.cylinderSource.SetRadius(getRadius());
        this.cylinderSource.SetResolution(getResolution());
        
        if (isCappingOn())
            this.cylinderSource.CappingOn();
        else
            this.cylinderSource.CappingOff();
        
        this.cylinderSource.Update();
    }

    /**
     * @return the center
     */
    public double[] getCenter() {
        return center;
    }

    /**
     * @param center the center to set
     */
    public void setCenter(double[] center) {
        this.center = center;
    }

    /**
     * @return the height
     */
    public double getHeight() {
        return height;
    }

    /**
     * @param height the height to set
     */
    public void setHeight(double height) {
        this.height = height;
    }

    /**
     * @return the radius
     */
    public double getRadius() {
        return radius;
    }

    /**
     * @param radius the radius to set
     */
    public void setRadius(double radius) {
        this.radius = radius;
    }

    /**
     * @return the resolution
     */
    public int getResolution() {
        return resolution;
    }
    
    /**
     * @return the cappingOn
     */
    public boolean isCappingOn() {
        return cappingOn;
    }

    /**
     * @param cappingOn the cappingOn to set
     */
    public void setCappingOn(boolean cappingOn) {
        this.cappingOn = cappingOn;
    }

    /**
     * @param resolution the resolution to set
     */
    public void setResolution(int resolution) {
        this.resolution = resolution;
    }
     
    public void setMaterial(double dieletric) {
        triangulatedCylinder = triangulatePolyData(cylinderSource.GetOutput());
        int nrOfCells = triangulatedCylinder.GetNumberOfCells(); 
        vtkDoubleArray scalars = new vtkDoubleArray();
        scalars.SetName("silicio");
        scalars.SetNumberOfComponents(1);
        scalars.SetNumberOfValues(nrOfCells);
        
        for (int i = 0; i < nrOfCells; i++) {
            scalars.SetValue(i, dieletric);
        }
        
        triangulatedCylinder.GetCellData().SetScalars(scalars);
        triangulatedCylinder.Modified();
    }
    
    @Override
    public vtkPolyData getPolyData() {
        return triangulatedCylinder;
    }
}
